﻿using LCL.Config;
using LCL.LData;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

namespace LCL.DbSqlMonitor
{
    public class OracleImpl :BaseImpl,ISQLMonitor
    {
        public OracleImpl(DbConfigInfo dbConfig):base(dbConfig)
        {
            
        }
        public DataTable GetSqlALL()
        {
            string sql =string.Format(@"select n.parsing_schema_name as 用户,
       n.module as 应用程序,
       dbms_lob.substr(n.sql_fulltext, 2000, 1) as sql语句,
       n.executions as sql执行次数,
       n.parse_calls as 解析次数,
       n.buffer_gets as 读内存次数,
       n.disk_reads as 读磁盘次数,
       n.cpu_time as cpu时间,
       n.elapsed_time as sql消耗时间,
       n.last_active_time as 最后执行时间
from v$sqlarea n where rownum <= {0} and n.parsing_schema_name = '{1}' 
and n.module not in ('PL/SQL Developer','SqlMonitor.exe','LCL.DbSqlMonitor.exe', 'plsqldev.exe', 'DBMS_SCHEDULER','JDBC Thin Client') 
order by n.last_active_time desc", this.RowNum, DbConfig.DbUser.ToUpper());

            return _dba.ExecuteDataTable(sql);
        }
        public bool DbLinkTest()
        {
            bool flg = true;
            try
            {
                string sql = "select sysdate from dual";
                _dba.ExecuteNonQuery(sql, null);
                flg = true;
            }
            catch (Exception e)
            {
                flg = false;
                Logger.Error("DbLinkTest:", e);
            }
            return flg;
        }
        public bool Clear()
        {
            return true;
        }
    }
}
